import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wangxin
 * Date: 2024-09-26
 * Time: 17:39
 */
public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        int n = in.nextInt();
        int m = in.nextInt();
        int x1 = in.nextInt() - 1;
        int y1 = in.nextInt() - 1;
        int x2 = in.nextInt() - 1;
        int y2 = in.nextInt() - 1;
        char[][] str = new char[n][m];
        for(int i = 0;i < n;i++){
            String str1 = in.next();
            for(int j = 0;j < m;j++){
                str[i][j] = str1.charAt(j);
            }
        }
        int sum = 0;
        for(int i = y1 + 1;i < y2;i++){
            int count = 0;
            for(int j = 0;j < m;j++){
                if(str[i][j] == '.'){
                    count++;
                }
            }
            sum = sum + count;
        }
        System.out.println(sum);

    }
}
//最短路径

 class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String[] s1=sc.nextLine().split(" ");
        int n=Integer.parseInt(s1[0]);
        int m=Integer.parseInt(s1[1]);
        String[] s2=sc.nextLine().split(" ");
        int sti=Integer.parseInt(s2[0]);
        int stj=Integer.parseInt(s2[1]);
        int ovi=Integer.parseInt(s2[2]);
        int ovj=Integer.parseInt(s2[3]);
        char[][] arr=new char[n][m];
        for(int i=0;i<n;i++){
            String s=sc.nextLine();

            for(int j=0;j<m;j++){
                arr[i][j]=s.charAt(j);
            }
        }
        if(arr[sti-1][stj-1]=='*' || arr[ovi-1][ovj-1]=='*') {
            System.out.println(-1);
            return;
        }
        Queue<int[]> queue=new LinkedList<>();
//        queue.offer(new Node(0,sti-1,stj-1));
        int[] node={0,sti-1,stj-1};
        queue.offer(node);
        int result=minStep(n,m,arr,ovi-1,ovj-1,queue);
        System.out.println(result);
    }
    public static int minStep(int n,int m,char[][] arr,int  ovi,int ovj,Queue<int[]> queue){
        while(queue.size()!=0) {
            int[] node = queue.poll();
            int step = node[0];
            int i = node[1];
            int j = node[2];
            if (i == ovi && j == ovj) return step;
            if (j + 1 < m && arr[i][j + 1] == '.') {
                int[] node1 = {step + 1, i, j + 1};
                queue.offer(node1);
                arr[i][j + 1] = '/';
            }
            if (i + 1 < n && arr[i + 1][j] == '.') {
                int[] node1 = {step + 1, i + 1, j};
                queue.offer(node1);
                arr[i + 1][j] = '/';
            }
            if (j - 1 >= 0 && arr[i][j - 1] == '.') {
                int[] node1 = {step + 1, i, j - 1};
                queue.offer(node1);
                arr[i][j - 1] = '/';
            }
            if (i - 1 >= 0 && arr[i - 1][j] == '.') {
                int[] node1 = {step + 1, i - 1, j};
                queue.offer(node1);
                arr[i - 1][j] = '/';
            }
        }
        return -1;
    }
}
